/* eslint-disable react/jsx-key */
import { Drawer } from 'antd';
import { useEffect, useState } from 'react';
import type { searchConfigInfo } from './data';
interface ParkProps {
  visible: boolean;
  onClose: () => void;
  detailData: searchConfigInfo;
}

export default (props: ParkProps) => {
  const { visible, onClose, detailData } = props;
  const [pickUp, setPickUp] = useState<boolean>(false);
  const chargeWayMAP = new Map().set(2, '对段加首重').set(1, '分段收费');
  const weightRulesMAP = new Map()
    .set(3, '进位至下一个0.5kg')
    .set(2, '四舍五入取整数')
    .set(1, '无规则');
  const shippingRulesMAP = new Map().set(2, '四舍五入取整数').set(1, '无规则');

  useEffect(() => {
    if (detailData.logisticsName == '京东特快重货' || detailData.logisticsName == '特快零担') {
      setPickUp(true);
    }
  }, []);
  const weightInterval = (str: number, array: number[]) => {
    let showInterval = `${str}`;
    for (let i = 0; i < array?.length; i++) {
      showInterval = showInterval + `-${array[i]}kg| ${array[i]}kg`;
    }
    return showInterval + '-∞';
  };
  const continuedWeight = (array: number[]) => {
    let showContinued = '';
    for (let i = 1; i < array.length; i++) {
      showContinued = showContinued + `${array[i] / 100}元 `;
    }
    return showContinued;
  };
  return (
    <Drawer
      title="计价规则"
      placement="right"
      width="360"
      onClose={() => {
        onClose();
      }}
      visible={visible}
    >
      <div>
        <p>物流名称：{detailData.logisticsName}</p>
        <p>最低价格：{detailData.lowCharge / 100}元</p>
        <p>起步重量：{detailData.startingWeight}kg</p>
        <p>首重价格：{detailData.weightPrice[0] / 100}元</p>
        <p>重量区间：{weightInterval(detailData.startingWeight, detailData.weightInterval)}</p>
        <p>续重：{continuedWeight(detailData.weightPrice)}</p>
        <p>重量进位规则：{weightRulesMAP.get(detailData.weightRules) || '-'}</p>
        <p>运费进位规则：{shippingRulesMAP.get(detailData.shippingRules) || '-'}</p>
        <p>收费方式：{chargeWayMAP.get(detailData.chargeWay) || '-'}</p>
        <p>省内打折：{detailData.provinceDiscount}折</p>
        <p>省外打折：{detailData.outsideDiscount}折</p>
        {!pickUp && <p>上楼取货：免费</p>}
        {pickUp && (
          <>
            <p>上楼取货：</p>
            <p>{'整票<=50KG,免费'}</p>
            <p>{'整票>50KG且<=140KG时，固定40元'}</p>
            <p>{'票整票>140KG, 0.3元/KG ,(最重件≥100KG,整票不上楼)'}</p>
          </>
        )}
      </div>
    </Drawer>
  );
};
